package com.yuwei.module_property

import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.lib_base.path.RouterPath
import com.bw.lib_common.view.BaseMvvmActivity
import com.yuwei.module_property.adapter.AreaAdapter
import com.yuwei.module_property.adapter.DistrictAdapter
import com.yuwei.module_property.databinding.ActivityPropertyBinding
import com.yuwei.module_property.viewmodel.PropertyViewModel
/**
 * 智慧园区-03-房源信息-列表页面-V1.1-20250507-邓孟卓
 */
@Route(path = RouterPath.MODULE_PROPERTY_ACTIVITY)
class PropertyActivity : BaseMvvmActivity<ActivityPropertyBinding>() {
    private val districtList : List<String> = listOf("A区", "B区", "C区", "D区")
    private val areaIdList : List<String> = listOf("1栋", "2栋", "3栋", "4栋")
    private val districtAdapter = DistrictAdapter()
    private val areaAdapter = AreaAdapter()
    private val vm : PropertyViewModel by viewModels()
    override fun initViews() {
        binding.propertyBack.setOnClickListener {
            finish()
        }
        districtAdapter.data.addAll(districtList)
        binding.propertyDistrictRv.adapter = districtAdapter
        binding.propertyDistrictRv.layoutManager = LinearLayoutManager(this,
            LinearLayoutManager.HORIZONTAL,false)
        areaAdapter.data.addAll(areaIdList)
        binding.propertyAreaRv.adapter = areaAdapter
        binding.propertyAreaRv.layoutManager = LinearLayoutManager(this)
        areaAdapter.addChildClickViewIds(R.id.iv_area_arrow)
        areaAdapter.setOnItemChildClickListener { adapter, view, position ->
            when(view.id){
                R.id.iv_area_arrow -> {
                    areaAdapter.setPosition(position)
                    areaAdapter.notifyDataSetChanged()
                    vm.getPropertyList(areaAdapter.getPosition()+1)
                }
            }
        }
        binding.propertyMore.setOnClickListener {
            ARouter.getInstance().build(RouterPath.MODULE_TENANT_ACTIVITY).navigation()
        }
    }
    override fun observeDataChange() {
        vm.getPropertySuccess.observe(this){

            areaAdapter.setRegionList(it)
            areaAdapter.notifyDataSetChanged()
        }
    }

    override fun getLayoutId(): Int = R.layout.activity_property

}